﻿package mortal.game.proxy
{
    import Framework.Util.*;
    import Message.Game.*;
    import Message.Public.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.common.error.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.mount.*;
    import mortal.mvc.core.*;

    public class MountProxy extends Proxy
    {
        private var _mountCache:MountCache;
        private var _isDelayArr:Array;

        public function MountProxy()
        {
            this._isDelayArr = new Array();
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this._mountCache = this.cache.mount;
            return;
        }// end function

        public function getPlayerMountInfo() : void
        {
            rmi.iMount.getPlayerMountInfo_async(new AMI_IMount_getPlayerMountInfo());
            return;
        }// end function

        public function setMountState(param1:int) : void
        {
            var _loc_2:* = getTimer();
            if (this._isDelayArr.length >= 3)
            {
                if (_loc_2 - this._isDelayArr[0] <= 1000)
                {
                    return;
                }
                this._isDelayArr.length = 0;
            }
            this._isDelayArr.push(_loc_2);
            var _loc_3:* = EMountState.convert(param1);
            if (CopyUtil.isInAllEscortTask)
            {
                MsgManager.showRollTipsMsg(Language.getString(70122));
                return;
            }
            rmi.iMount.setMountState_async(new AMI_IMount_setMountState(this.setStateSuceess, this.setStateFail, param1), _loc_3);
            return;
        }// end function

        private function setStateSuceess(param1:AMI_IMount_setMountState, param2:Boolean) : void
        {
            return;
        }// end function

        private function setStateFail(param1:Exception) : void
        {
            MsgManager.showRollTipsMsg(param1.code.toString());
            return;
        }// end function

        public function advance(param1:Boolean, param2:Dictionary, param3:Boolean) : void
        {
            rmi.iMount.advance_async(new AMI_IMount_advance(this.advanceSuccess, this.advanceFail, param3), param1, param2);
            return;
        }// end function

        private function advanceSuccess(param1:AMI_IMount_advance, param2:int) : void
        {
            var autoLevelUp:Function;
            var e:* = param1;
            var result:* = param2;
            autoLevelUp = function () : void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountAutoLevelup));
                return;
            }// end function
            ;
            if (result)
            {
                cache.mount.mountData.mountLevel = cache.mount.mountData.sPublicMount.code + 1;
                cache.mount.mountData.sPublicMount.bless = 0;
                cache.mount.mountData.sPublicMount.sharpId = cache.mount.mountData.mountLevel;
                NetDispatcher.dispatchCmd(ServerCommand.MountLevelUp, null);
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountCancelAutoLevelup));
                MsgManager.showMouseMsg(Language.getString(20587), MsgRollTipsType.msgRollTips2);
            }
            else if (e.userObject == true)
            {
                setTimeout(autoLevelUp, 200);
            }
            return;
        }// end function

        private function advanceFail(param1:Exception) : void
        {
            MsgManager.showRollTipsMsg(ErrorCode.getErrorStringByCode(param1.code));
            Dispatcher.dispatchEvent(new DataEvent(EventName.MountCancelAutoLevelup));
            return;
        }// end function

        public function dress(param1:String, param2:String) : void
        {
            rmi.iMount.dress_async(new AMI_IMount_dress(this.dressSuccess, this.advanceFail, param1), param1, param2);
            return;
        }// end function

        private function dressSuccess(param1:AMI_IMount_dress) : void
        {
            var _loc_3:ItemData = null;
            var _loc_2:* = param1.userObject as String;
            _loc_3 = Cache.instance.pack.mountPackCache.getItemDataByUid(_loc_2);
            if (_loc_3 && _loc_3.itemInfo.type == EEquipMount._EEquipMountShape)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WardrobeOpenWardrobe, EAdvanceComponentType._EAdvanceComponentTypeMount));
            }
            return;
        }// end function

        private function dressFail(param1:Exception) : void
        {
            MsgManager.showRollTipsMsg(ErrorCode.getErrorStringByCode(param1.code));
            return;
        }// end function

        public function activeCard(param1:int) : void
        {
            rmi.iMount.activeCard_async(new AMI_IMount_activeCard(this.activeSuccess), param1);
            return;
        }// end function

        private function activeSuccess(param1:AMI_IMount_activeCard) : void
        {
            return;
        }// end function

        private function activeFail(param1:Exception) : void
        {
            MsgManager.showRollTipsMsg(ErrorCode.getErrorStringByCode(param1.code));
            return;
        }// end function

        public function getCards(param1:int) : void
        {
            var _loc_2:* = EResetMode.convert(param1);
            rmi.iMount.getCards_async(new AMI_IMount_getCards(this.getSuccess, null, param1), _loc_2);
            return;
        }// end function

        private function getSuccess(param1:AMI_IMount_getCards, param2:Array) : void
        {
            var _loc_3:CDData = null;
            Cache.instance.mount.updateManureCards(param2);
            NetDispatcher.dispatchCmd(ServerCommand.MountManureCardUpdate, null);
            if (param1.userObject != EResetMode._EResetFirst)
            {
                var _loc_4:* = Cache.instance.mount;
                var _loc_5:* = Cache.instance.mount.currentAmount + 1;
                _loc_4.currentAmount = _loc_5;
            }
            if (param1.userObject != EResetMode._EResetFirst)
            {
                _loc_3 = Cache.instance.cd.registerCDData(CDDataType.backPackLock, "MountCardCD", _loc_3) as CDData;
                _loc_3.totalTime = 3600000;
                _loc_3.stopCoolDown();
                _loc_3.startCoolDown();
                NetDispatcher.dispatchCmd(ServerCommand.MountCardResetTimeUpdate, null);
            }
            return;
        }// end function

        public function openCard(param1:int) : void
        {
            rmi.iMount.openCard_async(new AMI_IMount_openCard(this.openSuccess), param1);
            return;
        }// end function

        private function openSuccess(param1:AMI_IMount_openCard, param2:SManureCard) : void
        {
            Cache.instance.mount.updateManureCard(param2);
            NetDispatcher.dispatchCmd(ServerCommand.MountManureCardOpen, param2);
            return;
        }// end function

        public function shuffleCard() : void
        {
            rmi.iMount.shuffleCard_async(new AMI_IMount_shuffleCard(this.shuffleSuccess));
            return;
        }// end function

        private function shuffleSuccess(param1:AMI_IMount_shuffleCard) : void
        {
            Cache.instance.mount.clearManureList();
            NetDispatcher.dispatchCmd(ServerCommand.MountCardShuffle, null);
            return;
        }// end function

        public function mountIllusion(param1:int) : void
        {
            rmi.iMount.changeMountShape_async(new AMI_IMount_changeMountShape(this.sharpSuccess, null, param1), param1);
            return;
        }// end function

        private function sharpSuccess(param1:AMI_IMount_changeMountShape) : void
        {
            return;
        }// end function

        public function getAdvanceReward(param1:int) : void
        {
            rmi.iMount.getAdvanceReward_async(new AMI_IMount_getAdvanceReward(), param1);
            return;
        }// end function

        public function changeShapeCard() : void
        {
            rmi.iMount.changeShapeCard_async(new AMI_IMount_changeShapeCard());
            return;
        }// end function

    }
}
